<?php

namespace App\Admin\Controllers;

use App\Models\ProductAttrVal;
use Encore\Admin\Controllers\AdminController;
use App\Admin\Actions\Post\Restore;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Illuminate\Http\Request;
use Redis;


class ProductAttrValController extends AdminController
{
    protected $title = '属性值列表';

    protected function grid()
    {
        $grid = new Grid(new ProductAttrVal());

        $grid->column('id', __('Id号'));
        $grid->column('attr_value', __('属性值'));
        $grid->column('created_at', __('创建时间'));
        $grid->column('updated_at', __('更新时间'));

        $grid->disableCreateButton();

        return $grid;
    }

    protected function detail($id)
    {
        $show = new Show(Product::findOrFail($id));

        $show->field('id', __('Id号'));
        $show->field('product_name', __('商品名称'));
        $show->field('cover_ico', __('封面图'))->image();
        $show->field('pics', __('主图'))->carousel();
        $show->field('member_price', __('价格'));
        $show->field('security', __('商品保障'));
        $show->field('sell_num', __('销量'));
        $show->field('num', __('余量'));
        $show->field('status', __('状态'))->using(['-1' => '删除', '0' => '未上架', '1' => '正常']);
        $show->field('created_at', __('创建时间'));
        $show->field('updated_at', __('更新时间'));

        return $show;
    }

    protected function form()
    {
        $form = new Form(new ProductAttrVal());
        $form->text('attr_value', __('属性值'));

        $form->footer(function ($footer) {
            // 去掉`继续编辑`checkbox
            $footer->disableEditingCheck();
        });

        return $form;
    }
}